package com.prime.tutorial.moviestore.dao;


import com.prime.tutorial.moviestore.domain.Device;
import com.prime.tutorial.moviestore.domain.DevicePort;
import com.prime.tutorial.moviestore.domain.Port;
import org.springframework.stereotype.Repository;

import javax.persistence.Query;
import java.util.List;

@Repository
public class DevicePortDAOWithJPA extends GenericDAOWithJPA<DevicePort, Long> implements DevicePortDAO {

    public List<DevicePort> findByPort(Port port) {
        Query query = entityManager.createQuery("Select distinct dp from DevicePort dp where dp.port.id = '"+port.getId()+"'");
        return query.getResultList();

    }

    public List<DevicePort> findByDevice(Device device) {
        Query query = entityManager.createQuery("Select distinct dp from DevicePort dp where dp.device.id = '"+device.getId()+"'");
        return query.getResultList();
    }
}